﻿using System;

namespace MyHealthByDesign.Views
{
    /// <summary>
    /// Description:
    /// Displays ParQ page
    /// 
    /// Author: Sanjeev Shrestha
    /// Date Created: 10/31/2011
    /// 
    /// Other code files referenced:
    /// None.
    /// 
    /// Regression Test Information:
    /// None.
    /// 
    /// Revision History:
    /// 11/03/2011 Sanjeev Shrestha - added logic for questionnaire.
    /// 11/08/2011 Sanjeev Shrestha - fix controls issue.
    /// 
    /// 
    /// Known Faults:
    /// None.
    /// </summary>
    public partial class ParQ : System.Web.UI.Page
    {
        Domain.Domain domain = new Domain.Domain();

        /// <summary>
        /// Page Load event handler - check if user is logged in
        /// 
        /// PreConditions:
        /// None
        /// 
        /// PostConditions:
        /// Page displayed
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!domain.IsUserLoggedIn())
            {
                Response.Redirect("../Default.aspx");
            }
        }

        /// <summary>
        /// Button click event handler - redirects based on logic
        /// 
        /// PreConditions:
        /// None
        /// 
        /// PostConditions:
        /// Page displayed
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            Response.Redirect(IsAnswerYes() ? "Notice.aspx" : "ParQGoodToGo.aspx");
        }

        /// <summary>
        /// IsAnswerYes - determines if a yes was selected on the form
        /// 
        /// PreConditions:
        /// None
        /// 
        /// PostConditions:
        /// returns boolean based on if yes was selected
        /// </summary>
        /// <returns></returns>
        private bool IsAnswerYes()
        {
            bool isYes = false;

            //check if any of the radio button is equal to 'Yes'
            if (rdBtnHeart1.Checked || rdBtnChest1.Checked ||
               rdBtnLastMonthChest1.Checked || rdBtnBalance1.Checked ||
               rdBtnJoint1.Checked || rdBtnDrugs1.Checked ||
               rdBtnReason1.Checked)
            {
                isYes = true;
            }

            return isYes;
        }
    }
}